package com.inossem.warehousestorage_inossem.utils;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;

import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.bean.query.QueryOutStorageDetailBean;
import com.inossem.warehousestorage_inossem.bean.query.QueryOutStorageListBean;
import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.data.Type;
import com.jzxiang.pickerview.listener.OnDateSetListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by leij on 2017/6/7.
 */

public class QueryUtils {

    public static TimePickerDialog getTimePickerDialog(Context context, Long time, Long minMillseconds, Long maxMillseconds, OnDateSetListener onDateSetListener) {
        TimePickerDialog.Builder yearMonthDay = new TimePickerDialog.Builder()
                .setType(Type.YEAR_MONTH_DAY)
                .setThemeColor(ContextCompat.getColor(context, R.color.include_header_background))
                .setCallBack(onDateSetListener)
                .setTitleStringId(context.getResources().getString(R.string.common_select_date))
                .setCyclic(false);
        if (minMillseconds != null) {
            yearMonthDay = yearMonthDay.setMinMillseconds(minMillseconds);
        }
        if (maxMillseconds != null) {
            yearMonthDay = yearMonthDay.setMaxMillseconds(maxMillseconds);
        }
        if (time == null) {
            yearMonthDay.setCurrentMillseconds(System.currentTimeMillis());
        } else {
            yearMonthDay.setCurrentMillseconds(time);
        }
        return yearMonthDay.build();
    }

    public static SpannableStringBuilder changeFontColor(Context context, String colorInfo, String info, int color) {
        SpannableStringBuilder builder = new SpannableStringBuilder(colorInfo + info);
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(ContextCompat.getColor(context, color));
        builder.setSpan(colorSpan, 0, colorInfo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return builder;
    }


    public static List<QueryOutStorageListBean.DataBean.OutStorageListBean> filterOutStorageList(List<QueryOutStorageListBean.DataBean.OutStorageListBean> allData, String outStorageNumber) {
        List<QueryOutStorageListBean.DataBean.OutStorageListBean> result = new ArrayList<>();
        for (int i = 0; i < allData.size(); i++) {
            QueryOutStorageListBean.DataBean.OutStorageListBean outStorageItem = allData.get(i);
            if (outStorageItem.getOutStorageNumber().contains(outStorageNumber)) {
                result.add(outStorageItem);
                continue;
            }
        }
        return result;
    }

    public static List<QueryOutStorageDetailBean.DataBean.PositionListBean> filterPositionList(List<QueryOutStorageDetailBean.DataBean.PositionListBean> allData, String position) {
        List<QueryOutStorageDetailBean.DataBean.PositionListBean> result = new ArrayList<>();
        for (int i = 0; i < allData.size(); i++) {
            QueryOutStorageDetailBean.DataBean.PositionListBean positionItem = allData.get(i);
            if (positionItem.getPosition().contains(position)) {
                result.add(positionItem);
                continue;
            }
        }
        return result;
    }
}
